﻿namespace ResumableDownload.View
{
    using System;
    using System.IO;
    using System.IO.IsolatedStorage;
    using System.Windows;
    using System.Windows.Media;
    using ViewModel;

    public partial class Mp3Page
    {
        public Mp3Page()
        {
            InitializeComponent();

            this.mediaElement.MediaFailed += this.HandleFailed;
        }

        private void HandleFailed(object sender, ExceptionRoutedEventArgs e)
        {
        }

        private void PlayClick(object sender, System.Windows.RoutedEventArgs e)
        {
            var source = ((Mp3ViewModel) DataContext).Source;
            var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
            var stream = isoFile.OpenFile(source, FileMode.Open);
            this.mediaElement.SetSource(stream);
            this.mediaElement.Play();
        }

        private void StopClick(object sender, System.Windows.RoutedEventArgs e)
        {
            this.mediaElement.Stop();
            this.mediaElement.Source = null;
        }
    }
}
